from django.db import models
from django.utils import timezone
from user_app.models import User
from subjects_app.models import Subject  # 导入Subject模型

class ExaminationQuestions(models.Model):
    question = models.TextField(blank=True, null=True, verbose_name="问题文本")  # 问题文本
    options = models.TextField(blank=True, null=True, verbose_name="选项文本")  # 选项文本，用逗号分隔
    answer = models.TextField(blank=True, null=True, verbose_name="答案")  # 正确答案
    explanation = models.TextField(blank=True, null=True, verbose_name="答案解释")  # 答案解释
    # create_at = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
    # update_at = models.DateTimeField(auto_now=True,verbose_name='更新时间')
    question_type = models.IntegerField(null=True,blank=True, choices=((1, '单项选择题'), (2, '多项选择题'),(3, '判断题'),(4, '问答题'), (5, '病例分析')), verbose_name='问题类型')  # 问题类型，如单选、多选等
    question_class = models.IntegerField(null=True,blank=True,choices=((1,'护理学基础'), (2,'内科护理学'), (3, '外科护理学'), (4, '护理学导论')), verbose_name='问题所属学科')  # 问题所属类别，如科目、章节等
    question_source = models.ForeignKey(Subject, on_delete=models.CASCADE , verbose_name='问题来源')  # 问题来源，如考试、模拟考试等

    class Meta:
        db_table = 't_examination_questions'  # 指定表名
        verbose_name = '试题'
        verbose_name_plural = '试题'



class UserAnswerRecord(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)  # 关联用户
    question = models.ForeignKey(ExaminationQuestions, on_delete=models.CASCADE)  # 关联题目
    answer = models.TextField(blank=True, null=True, verbose_name="答案文本")  # 答题
    create_at = models.DateTimeField(auto_now_add=True)  # 答题时间

    def __str__(self):
        return f"{self.user.username} - {self.question.question}"

    class Meta:
        db_table = 't_user_answer_record'  # 指定表名
        
